define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'trans_limits_warn/index' + location.search,
                    // add_url: 'trans_limits_warn/add',
                    // edit_url: 'trans_limits_warn/edit',
                    // del_url: 'trans_limits_warn/del',
                    multi_url: 'trans_limits_warn/multi',
                    import_url: 'trans_limits_warn/import',
                    table: 'trans_limits_warn',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'name', title: __('Uid') },
                        { field: 'times', title: __('Times') },
                        { field: 'limitVal', title: __('限制金额') },
                        { field: 'procNick', title: __('Process') },
                        { field: 'create_time', title: __('Create_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'process_time', title: __('Process_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'status', title: __('Status'), searchList: { "1": __('Status 1'), "2": __('Status 2') }, formatter: Table.api.formatter.status },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'bank',
                                title: __('详细信息'),
                                // text: __('收款信息'),
                                icon: 'fa fa-bitcoin',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'trans_limits_warn/details'
                            }, {
                                name: 'qrcode',
                                title: __('一键拨号'),
                                // text: __('接收'),
                                icon: 'fa fa-phone-square',
                                classname: 'btn btn-primary btn-xs btn-detail btn-dialog',
                                url: 'Machine/qr',
                                extend: 'data-area=\'["450px", "450px"]\''
                            }],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});